/**
 *
 */
package tec.data.persistence.oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import oracle.jdbc.pool.OracleDataSource;

public class ThinConnectionHelper {
	public Connection getConnection(BasicConnectionParameter p) throws SQLException {
		OracleDataSource ods = new OracleDataSource();
		
		ods.setServerName(p.getHost());
		ods.setPortNumber(p.getPort());
		ods.setDatabaseName(p.getSid());
		ods.setUser(p.getUserName());
		ods.setPassword(p.getPassword());
		ods.setDriverType("thin");
		
		return(ods.getConnection());
	}
	
	public Connection getJDBCConnection(BasicConnectionParameter p) throws SQLException {
		// register oracle driver
		//Class.forName("oracle.jdbc.driver.OracleDriver");
		
		// alternative method to register oracle driver
		DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
		
		/*
		 * Oracle connection string : 
		 * - jdbc:oracle:thin:@host:port:sid
		 * - jdbc:oracle:thin:user/password@host:port:sid
		 */
		String url = "jdbc:oracle:thin:@" + 
						p.getHost() + ":" + 
						p.getPort() + ":" + 
						p.getSid();
		String user = p.getUserName();
		String password = p.getPassword();
		Connection con = DriverManager.getConnection(url, user, password);
		
		return(con);
	}
}
